package weka.console;


import java.io.BufferedReader;
import java.io.InputStreamReader;


public class CommandPrompt {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println("---main : Weka console run through weka.jar");
 
		
		consoleRun("weka.classifiers.trees.J48","/home/ugur/weka/data/weather.arff");
		guiRun();
	}
	
	public static String guiRun(){
		//weka.gui.GUIChooser.main(null);
		return "Weka GUI is triggered";
	} // end of method guiRun
	
	public static String consoleRun(String _mlAlgorithm , String _dataFilePath){
		
		System.out.println("---Weka consoleRun through weka.jar");
		String consoleOutput="";

		String mlAlgorithm = _mlAlgorithm;
		String dataFilePath = _dataFilePath;
		
		try {
			
		      String line;
		      Process p = Runtime.getRuntime().exec("java -cp /home/ugur/weka/weka.jar  "+ mlAlgorithm +" -t "+  dataFilePath  +" -i");
		      BufferedReader input =
		        new BufferedReader
		          (new InputStreamReader(p.getInputStream()));
		      while ((line = input.readLine()) != null) {
		    	  consoleOutput = consoleOutput + "\n" + line;
		      }
		      input.close();
		    }
		    catch (Exception err) {
		      err.printStackTrace();
		    }

	    	   System.out.println(consoleOutput);

		
		return consoleOutput;
	}// end of method consoleRun

}// end of class
